package com.hao.cdk.sm.core.mabatisplus;

import com.baomidou.mybatisplus.annotation.DbType;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * @author: 许自豪
 * @date: 2025-01-23 17:12:08
 * @description: MybatisPlus自动配置相关参数
 */
@Component
@ConfigurationProperties("mybatis-plus.interceptors.pagination")
@EnableConfigurationProperties({PaginationProperties.class})
public class PaginationProperties {
    private boolean overflow = false;
    private long maxLimit = 50L;
    private DbType dbType;
    private String dialectClassName;

    public PaginationProperties() {
        this.dbType = DbType.MYSQL;
    }

    public boolean isOverflow() {
        return this.overflow;
    }

    public long getMaxLimit() {
        return this.maxLimit;
    }

    public DbType getDbType() {
        return this.dbType;
    }

    public String getDialectClassName() {
        return this.dialectClassName;
    }

    public void setOverflow(final boolean overflow) {
        this.overflow = overflow;
    }

    public void setMaxLimit(final long maxLimit) {
        this.maxLimit = maxLimit;
    }

    public void setDbType(final DbType dbType) {
        this.dbType = dbType;
    }

    public void setDialectClassName(final String dialectClassName) {
        this.dialectClassName = dialectClassName;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        PaginationProperties that = (PaginationProperties) o;
        return overflow == that.overflow && maxLimit == that.maxLimit && dbType == that.dbType && Objects.equals(dialectClassName, that.dialectClassName);
    }

    @Override
    public int hashCode() {
        return Objects.hash(overflow, maxLimit, dbType, dialectClassName);
    }

    @Override
    public String toString() {
        return "PaginationProperties{" +
                "overflow=" + overflow +
                ", maxLimit=" + maxLimit +
                ", dbType=" + dbType +
                ", dialectClassName='" + dialectClassName + '\'' +
                '}';
    }
}
